package com.partner.frame;

import javax.servlet.http.*;

import org.apache.log4j.*;
import org.springframework.stereotype.*;

@Service("tokenService")
public class TokenService
{
   private final static Logger logClass = Logger.getLogger(TokenService.class);

   public final static String CUSTOM_SESSION_IDENT = "customId";
   public final static String CUSTOM_SESSION_TOKEN = "customToken";
   
   public final static int SESSION_INACTIVE_MAXTIME = 60;//*60*12;
   
   public void addCustomSession(String strCustomIdent, HttpServletRequest httpRequest)
   {
      HttpSession customSession = null;
      //设置登录session
      customSession = httpRequest.getSession(false);
      if(customSession == null)
      {
         customSession = httpRequest.getSession(true);
         customSession.setMaxInactiveInterval(SESSION_INACTIVE_MAXTIME);
      }
      customSession.setAttribute(CUSTOM_SESSION_IDENT, strCustomIdent);
      
      
      return;
   }
   
   public String getFromSession(HttpServletRequest httpRequest)
   {
      String strCustomIdent = null;
      HttpSession customSession = null;
      
      //设置登录session
      customSession = httpRequest.getSession(false);
      if(customSession != null)
      {
         strCustomIdent = (String) customSession.getAttribute(CUSTOM_SESSION_IDENT);
      }
      
      return strCustomIdent;
   }
   
}
